package com.martin.lib_base.ktx

import android.view.View
import android.widget.Toast
import com.xuexiang.xui.utils.SnackbarUtils
import com.xuexiang.xui.utils.XToastUtils
import com.xuexiang.xui.widget.toast.XToast
import dev.DevUtils
import dev.utils.app.HandlerUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

/**
 * @author：Houge
 * @date：2022/11/11
 * @desc：吐司扩展
 */

fun normalToast(msg: String, isShort: Boolean = true) {
    HandlerUtils.postRunnable {
        if (isShort) {
            XToastUtils.toast(msg, Toast.LENGTH_SHORT)
        } else {
            XToastUtils.toast(msg, Toast.LENGTH_LONG)
        }
    }
}

fun infoToast(msg: String, isShort: Boolean = true) {
    HandlerUtils.postRunnable {
        if (isShort) {
            XToastUtils.info(msg, Toast.LENGTH_SHORT)
        } else {
            XToastUtils.info(msg, Toast.LENGTH_LONG)
        }
    }
}

fun warningToast(msg: String, isShort: Boolean = true) {
    HandlerUtils.postRunnable {
        if (isShort) {
            XToastUtils.warning(msg, Toast.LENGTH_SHORT)
        } else {
            XToastUtils.warning(msg, Toast.LENGTH_LONG)
        }
    }
}

fun successToast(msg: String, isShort: Boolean = true) {
    HandlerUtils.postRunnable {
        if (isShort) {
            XToastUtils.success(msg, Toast.LENGTH_SHORT)
        } else {
            XToastUtils.success(msg, Toast.LENGTH_LONG)
        }
    }
}

fun errorToast(msg: String, isShort: Boolean = true) {
    HandlerUtils.postRunnable {
        if (isShort) {
            XToastUtils.error(msg, Toast.LENGTH_SHORT)
        } else {
            XToastUtils.error(msg, Toast.LENGTH_LONG)
        }
    }
}

fun snack(msg: String, view: View, isShort: Boolean = true) {
    HandlerUtils.postRunnable {
        if (isShort) {
            SnackbarUtils.Short(view, msg)
        } else {
            SnackbarUtils.Long(view, msg)
        }
    }
}
